package com.yqya.springboot.mybatisplus.shardingjdbc.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置
 *
 * @author Kevin
 * @date 2019-08-03
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    /**
     * 是否开启swagger
     */
    @Value("${swagger.switch}")
    private boolean swaggerSwitch;

    @Bean
    public Docket api() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        docket.enable(swaggerSwitch);
        docket.apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yqya.springboot.mybatisplus.shardingjdbc.controller"))
                .paths(PathSelectors.any()).build();
        return docket;
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("分库分表读写分离整合示例")
                .description("SpringBoot + MyBatisPlus + ShardingJDBC 分库分表读写分离整合示例")
                .contact(new Contact("白凤", "http://www.youqianyouai.com", ""))
                .termsOfServiceUrl("http://www.youqianyouai.com")
                .version("1.0")
                .build();
    }

}
